﻿package plugin.emailui.handler
{
    import com.core.*;
    import flash.utils.*;
    import plugin.emailui.*;
    import pluginfw.nio.*;
    import pluginfw.nio.imsg.*;

    public class EmailGroupHandler extends Object implements IGroupHandler
    {
        private var _cfgitems:Object;

        public function EmailGroupHandler()
        {
            this._cfgitems = ConfigDictionary.data.item;
            return;
        }// end function

        public function dealSimpleMessage(param1:ISimpleMessage) : void
        {
            return;
        }// end function

        public function dealBufferMessage(param1:IBufferMessage) : void
        {
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Object = null;
            var _loc_9:Object = null;
            var _loc_2:* = new Object();
            var _loc_3:* = new Input(null);
            var _loc_4:* = param1.getBody();
            switch(param1.getCmd())
            {
                case CMDEmail.GetEmailBack:
                {
                    _loc_4.position = 0;
                    _loc_3.setBytes(_loc_4);
                    _loc_2.emailList = new Array();
                    _loc_6 = _loc_3.readShort();
                    _loc_7 = 0;
                    while (_loc_7 < _loc_6)
                    {
                        
                        _loc_5 = _loc_3.readByte();
                        if (_loc_2.emailList[_loc_7] == null)
                        {
                            _loc_2.emailList[_loc_7] = new Object();
                        }
                        if (_loc_5 != 0)
                        {
                            _loc_2.emailList[_loc_7].emailId = _loc_3.readVarInt(false);
                            _loc_2.emailList[_loc_7].from = _loc_3.readString();
                            _loc_2.emailList[_loc_7].title = _loc_3.readString();
                            _loc_2.emailList[_loc_7].desc = _loc_3.readString();
                            _loc_2.emailList[_loc_7].items = _loc_3.readString();
                            _loc_2.emailList[_loc_7].state = _loc_3.readByte();
                            _loc_2.emailList[_loc_7].time = _loc_3.readVarInt(false);
                        }
                        _loc_7++;
                    }
                    ModelProxy.change("email", "show", _loc_2.emailList);
                    ModelProxy.change("data", "emailData", _loc_2.emailList);
                    if (!ModelProxy.getValue("data", "emailIsInit"))
                    {
                        for each (_loc_9 in _loc_2.emailList)
                        {
                            
                            if (_loc_9.state < 2)
                            {
                                ModelProxy.change("mainui", "showemail", true);
                                break;
                            }
                        }
                    }
                    break;
                }
                case CMDEmail.HasEmail:
                {
                    _loc_4.position = 0;
                    _loc_3.setBytes(_loc_4);
                    _loc_2.emailId = _loc_3.readVarInt(false);
                    break;
                }
                case CMDEmail.Change:
                {
                    _loc_4.position = 0;
                    _loc_3.setBytes(_loc_4);
                    _loc_2.email = new Array();
                    _loc_6 = _loc_3.readShort();
                    _loc_7 = 0;
                    while (_loc_7 < _loc_6)
                    {
                        
                        _loc_5 = _loc_3.readByte();
                        if (_loc_2.email[_loc_7] == null)
                        {
                            _loc_2.email[_loc_7] = new Object();
                        }
                        if (_loc_5 != 0)
                        {
                            _loc_2.email[_loc_7].emailId = _loc_3.readVarInt(false);
                            _loc_2.email[_loc_7].from = _loc_3.readString();
                            _loc_2.email[_loc_7].title = _loc_3.readString();
                            _loc_2.email[_loc_7].desc = _loc_3.readString();
                            _loc_2.email[_loc_7].items = _loc_3.readString();
                            _loc_2.email[_loc_7].state = _loc_3.readByte();
                            _loc_2.email[_loc_7].time = _loc_3.readVarInt(false);
                        }
                        _loc_7++;
                    }
                    ModelProxy.change("email", "change", _loc_2.email);
                    break;
                }
                case CMDEmail.AddEmail:
                {
                    _loc_4.position = 0;
                    _loc_3.setBytes(_loc_4);
                    _loc_2.email = new Object();
                    _loc_5 = _loc_3.readByte();
                    if (_loc_5 > 0)
                    {
                        _loc_2.email.emailId = _loc_3.readVarInt(false);
                        _loc_2.email.from = _loc_3.readString();
                        _loc_2.email.title = _loc_3.readString();
                        _loc_2.email.desc = _loc_3.readString();
                        _loc_2.email.items = _loc_3.readString();
                        _loc_2.email.state = _loc_3.readByte();
                        _loc_2.email.time = _loc_3.readVarInt(false);
                    }
                    _loc_8 = ModelProxy.getValue("data", "emailData");
                    _loc_8.push(_loc_2.email);
                    ModelProxy.change("email", "addemail", _loc_2.email);
                    ModelProxy.change("mainui", "showemail", null);
                    break;
                }
                case CMDEmail.DeleteBack:
                {
                    _loc_4.position = 0;
                    _loc_3.setBytes(_loc_4);
                    _loc_2.emailIdList = new Array();
                    _loc_6 = _loc_3.readShort();
                    _loc_7 = 0;
                    while (_loc_7 < _loc_6)
                    {
                        
                        _loc_2.emailIdList[_loc_7] = _loc_3.readVarInt(false);
                        _loc_7++;
                    }
                    ModelProxy.change("email", "delete", _loc_2.emailIdList);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function dealProxyMessage(param1:IProxyMessage) : void
        {
            return;
        }// end function

    }
}
